home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-02 | 5.8 KB | 208 lines | [TEXT/MMCC] |
- /************************************************************************************
-
- File: MathComponent.c
-
- Contains: Math component routines.
-
- Written by: Gary Woodcock
-
- Copyright: © 1992 by Apple Computer, Inc.
-
- Change History (most recent first):
-
-
- Project settings for 68K
- Code model: Small, Smart or Large
- Link Single Segment: on (VERY important)
- Project type: Code Resource
- File name: Math_Component
- Sym name: Math_Component.SYM (not generated)
- Resource name: Math Component
- Header type: Standard
- Multi Segment: on or off
- ResType: _68K
- ID: 128
- SegType blank (unused since we are linking single segment)
- Creator: gwck
- File type: thng
- Resource flags: SysHeap
- Project setup:
- Segment 1 (Main Segment): MathComponent.c
- Segment 2 (Group2): MacOS.lib, FatMathComponent.rsrc (See warning below)
- Segment 3 (Group3): and MathComponentCommon.c
-
- Project settings for PPC
- Project type: Code Resource
- File name: Math_Component
- Sym name: Math_Component.SYM (not generated)
- Resource name: Math Component
- Header type: None (VERY important)
- ResType: _PPc
- ID: 128
- Creator: gwck
- File type: thng
- Resource flags: SysHeap
- Merge To File on
- Expand Uninitialized Data: on
- Main Entry Point MainRD (VERY important)
- Project setup:
- Group 1 (Main Group): MathComponent.c
- Group 2 (Group2): InterfaceLib, MathLib, ToolsLib.o
- Group 3 (Group3): MathComponentCommon.c
-
- ***Warning*** FatMathComponent.rsrc has an extended thng resource which
- is set to require both PPC and 68K code. If you want to test the 68K
- component by itself, use MathComponent.rsrc, instead.
-
- CW components need to have the Link Single Segment switch checked. The Multi-
- segment switch can be checked or unchecked as fits your needs. (Please
- see the User Guide for which situations require the Multi-segment switch.)
- Putting everything into one segment eliminates segment loader errors that
- would occur if the startup code tried to call GetResource before
- OpenComponentResFile is called. Components written in C are moveable, components
- written in C++ with virtual functions probably aren't. Please see the
- C++ XCMD example on the CD for an example of how to deal C++ code resources.
-
- Project settings, port to PPC and comments by
- Mark Anderson
- metrowerks
- 12/1/94
-
- ************************************************************************************/
-
- //-----------------------------------------------------------------------
- // includes
-
- #include "MathComponent.h"
- #include "MathComponentPrivate.h"
- #include "MathComponentCommon.h"
- #include <Errors.h>
- #ifndef powerc
- #include <A4Stuff.h>
- #endif
-
-
- //-----------------------------------------------------------------------
- // Prototype (can't be in header or there is a conflict with Component Tester)
- #ifndef DEBUG_IT
- pascal ComponentResult main (ComponentParameters *params,
- Handle storage);
- #endif
-
- //-----------------------------------------------------------------------
- //PPC Globals
- #ifdef powerc
-
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathCanDo);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathOpen);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathClose);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathVersion);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathTarget);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoDivide);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoMultiply);
-
- #ifndef DEBUG_IT
- RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(uppComponentRoutineProcInfo, main);
- ProcInfoType __procinfo = uppComponentRoutineProcInfo;
- #endif
- #endif
-
- //-----------------------------------------------------------------------
- #ifdef DEBUG_IT
-
- // Use this declaration when we're running linked (for debugging)
- pascal ComponentResult MathDispatcher (ComponentParameters *params,
- Handle storage)
-
- #else
-
- // Use this declaration when we're a standalone component
- pascal ComponentResult main (ComponentParameters *params,
- Handle storage)
-
- #endif DEBUG_IT
-
- {
- // This routine is the main dispatcher for the Math component
-
- ComponentResult result = noErr;
-
- #if !defined(powerc) && !defined(DEBUG_IT)
- long oldA4;
-
- oldA4 = SetCurrentA4();
- #endif
-
- // Did we get a Component Manager request code (< 0)?
- if (params->what < 0)
- {
- switch (params->what)
- {
- case kComponentOpenSelect: // Open request
- {
- result = CallComponentFunctionUniv(params, MathOpen);
- break;
- }
- case kComponentCloseSelect: // Close request
- {
- //if open fails, close gets called (why I don't know) so
- //globals aren't allocated
- if (!storage)
- return result;
- result = CallComponentFunctionWithStorageUniv(storage, params, MathClose);
- break;
- }
- case kComponentCanDoSelect: // Can Do request
- {
- result = CallComponentFunctionUniv(params, MathCanDo);
- break;
- }
- case kComponentVersionSelect: // Version request
- {
- result = CallComponentFunctionUniv(params, MathVersion);
- break;
- }
- case kComponentTargetSelect: // Target request
- {
- result = CallComponentFunctionWithStorageUniv(storage, params, MathTarget);
- break;
- }
- case kComponentRegisterSelect: // Register request not supported
- default: // Unknown request
- {
- result = paramErr;
- break;
- }
- }
- }
- else // Was it one of our request codes?
- {
- switch (params->what)
- {
- case kDoDivideSelect: // Divide request
- {
- result = CallComponentFunctionUniv(params, MathDoDivide);
- break;
- }
- case kDoMultiplySelect: // Multiply request
- {
- result = CallComponentFunctionUniv(params, MathDoMultiply);
- break;
- }
-
- default: // Unknown request
- {
- result = paramErr;
- break;
- }
- }
- }
-
- #if !defined(powerc) && !defined(DEBUG_IT)
- SetA4(oldA4);
- #endif
-
- return (result);
- }
-
-